#include <iostream>
#include <fstream>
#include <math.h>

#define POW5(a) ((a)*(a)*(a)*(a)*(a))

using namespace std;
bool capic(long int n);

int main()
{
    long int sum = 0;
for (int n = 2;n<10000000 ; n++)
{
    if(capic(n))
    {
        cout << n << endl;
        sum = sum + n;
    }
}
cout << sum;
}

bool capic(long int n){
    int a,b,c,d,e,f,g;
    a = n % 10;
    b = (n / 10) % 10;
    c = (n / 100) % 10;
    d = (n / 1000) % 10;
    e = (n / 10000) % 10;
 f = (n / 100000) % 10;
  g = (n / 1000000) % 10;
return (n == (pow(a,5) + pow(b,5) + pow(c,5) + pow(d,5) + pow(e,5)+ pow(f,5)+ pow(g,5)));
    }
